﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace company_present
{
    public partial class DetailNews : ModuleCompanyBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Request["detail"] != null)
            {
               
                if (!IsPostBack)
                {
                    if (Request["newsid"] != null)
                    {


                        int newsid;
                        if (int.TryParse(Request["newsid"], out newsid))
                        {

                            var news = (from nw in DB.cp_News where nw.ID == newsid && nw.Visible.Value select nw).FirstOrDefault();

                            if (news != null)
                            {
                                this.title.InnerHtml = news.Title;
                                this.createdate.InnerHtml = news.CreateDate.Value.ToString("dd/MM/yyyy");

                                this.content.InnerHtml = HttpUtility.HtmlDecode(news.Content);


                                List<cp_New> newer = (from nw in DB.cp_News
                                                      where (nw.CreateDate.Value > news.CreateDate.Value || nw.CreateDate.Value == news.CreateDate.Value)
                                                      && nw.ID != news.ID && nw.TabID == nw.TabID && nw.Visible.Value
                                                      orderby nw.CreateDate.Value ascending
                                                      select nw).Distinct().Take(5).ToList<cp_New>();

                                List<cp_New> older = (from nw in DB.cp_News
                                                      where (nw.CreateDate.Value < news.CreateDate.Value || nw.CreateDate.Value == news.CreateDate.Value)
                                                      && nw.ID != news.ID && news.TabID == news.TabID
                                                      orderby nw.CreateDate.Value descending
                                                      select nw).Distinct().Take(10).ToList<cp_New>();

                                this.newer.DataSource = newer;
                                this.newer.DataBind();

                                this.older.DataSource = older;
                                this.older.DataBind();

                            }

                        }

                    }
               
                }

            }
            else
            {


                this.ctNewslast.Visible = false;
                this.ctNewsNews.Visible = false;
            }
        }
    }
}